#include "selection_list_model.h"
#include <QColor>

SelectionListModel::SelectionListModel(  const SelectionPair& selections ,  QObject *parent)
    : QAbstractListModel(parent),selections_(selections)
{
}

QVariant SelectionListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    return QVariant();
}

int SelectionListModel::rowCount(const QModelIndex &parent) const
{
    // For list models only the root node (an invalid parent) should return the list's size. For all
    // other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
    if (parent.isValid())
        return 0;
    return selections_.size();
    // FIXME: Implement me!
}

bool SelectionListModel::hasChildren(const QModelIndex &parent) const
{
    return  false;
}

bool SelectionListModel::canFetchMore(const QModelIndex &parent) const
{
    // FIXME: Implement me!
    return false;
}

void SelectionListModel::fetchMore(const QModelIndex &parent)
{
    // FIXME: Implement me!
}

QVariant SelectionListModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();
    switch (role) {
    case Qt::TextAlignmentRole:
        return Qt::AlignCenter;
    case Qt::DisplayRole:
        return selections_.at(index.row()).name;
    case Qt::EditRole:
        return selections_.at(index.row()).value;
    }
    return QVariant();
}
